-module(state).
-export([start/1, get/0, set/1]).
-export([loop/1]).

start(State) ->
    Pid = spawn(?MODULE, loop, [State]),
    register(state, Pid).

get() ->
    state ! {get, self()},
    receive
	{replay, State} -> 
	    State
    end.

set(NewState) ->
    state ! {set, NewState}.

loop(State) ->
    receive
	{get, Pid} ->
	    Pid ! {replay, State},
	    loop(State);
	{set, NewState} ->
	    loop(NewState);
	stop ->
	    ok
    end.
